package com.xgpro.pc.handleaffairs.controller;

import com.xgpro.common.controller.BaseController;
import com.xgpro.common.exceptions.BusinessRuntimeException;
import com.xgpro.common.results.ResponseResult;
import com.xgpro.domain.handleaffairs.dto.HandleAffairsDto;
import com.xgpro.domain.handleaffairs.dto.HandleAffairsUpload;
import com.xgpro.domain.studycentre.vo.PlanFront;
import com.xgpro.domain.studycentre.vo.PlanPCFront;
import com.xgpro.pc.handleaffairs.service.HandleAffairsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author xy
 * @version 1.0
 * @date 2019/10/15 20:43
 */
@RestController
@RequestMapping("/handleAffairs")
@CrossOrigin(allowCredentials="true")
public class HandleAffairsController extends BaseController {

    @Autowired
    private HandleAffairsService handleAffairsService;

    /**
     * 文件列表
     * @param handleAffairsDto
     * @return
     */
    @RequestMapping("/qryHandleAffairsList")
    public ResponseResult qryHandleAffairsList(@RequestBody HandleAffairsDto handleAffairsDto){
        return ResponseResult.ok(handleAffairsService.qryHandleAffairsList(handleAffairsDto));
    }

    /**
     * 根据id删除文件
     * @param id
     * @return
     */
    @RequestMapping("/deleteByHandleAffairsId")
    public ResponseResult deleteByHandleAffairsId(Integer id){
        return ResponseResult.ok(handleAffairsService.deleteByHandleAffairsId(id));
    }

    /**
     * 上传文件
     * @param handleAffairsUpload
     * @return
     * @throws IOException
     */
    @RequestMapping("/insertHandleAffairs")
    public ResponseResult insertHandleAffairs( HandleAffairsUpload handleAffairsUpload) throws IOException{
        try{
            return ResponseResult.ok(handleAffairsService.insertHandleAffairs(handleAffairsUpload));
        }catch (BusinessRuntimeException e){
            return ResponseResult.failure(e.getErrorCode(),e.getMessage());
        }
    }

    /**
     * 下载计划
     * @param id
     * @return
     */
    @RequestMapping("/downloadHandleAffairs")
    public ResponseResult downloadHandleAffairs(@RequestParam Integer id) {
        return handleAffairsService.downloadHandleAffairs(id);
    }
}
